program tangqiao;

const max=200;

type kkk=^jjj;
     jjj=record
           val:longint;
           next:kkk;
         end;



var p,q,first,last,o:kkk;
    n,time:integer;


procedure input;   {**** input the information ****}
 begin
   writeln;
   writeln('Input');
   readln(n,time);
 end;

procedure init;
 var i:integer;
 begin

   new(p);

   p^.val:=1;
   first:=p;
   for i:=2 to n do
     begin
       new(q);
       q^.val:=i;
       p^.next:=q;
       p:=q;
     end;
   q^.next:=first;
   last:=q;
 end;

procedure out;

 begin
   o:=p;
   p:=p^.next;
   q^.next:=p;
   dispose(o);
 end;



procedure course;
 var chi,i,j:integer;
 begin
   p:=first;
   q:=last;
   for j:=1 to n-1 do
     begin
       for i:=1 to time-1 do
          begin
            p:=p^.next;
            q:=q^.next;
          end;
       out;
     end;
 end;




procedure output;  {**** output the information ***}
 var i:integer;
 begin
   writeln('Output');
   writeln('the winner is No.',p^.val);
 end;

begin
  input;

  init;

  course;

  output;
end.
